﻿$(function(){
    $("#submit").click(function(){
        $("#deviceForm").validate("validate").done(function(result){
            var device={
                title:$("#title").val(),
                tags:$("#tags").val(),
                about:$("#about").val(),
                local:$("#local").val(),
                site_flag:$("#site_flag").val()
            }
            console.log(device);
            $.getJsonData(contextPath+"/device",device,{type:"Post"}).done(function(data){
                console.log(data);
                if(data.success){
                window.location.href=contextPath+"dev_suc_add.html";
                    //moon.info("添加成功","top");
                }else{
                    moon.error("添加失败","top");
                }
            }).fail(function(e){
                console.log(e);
            });
        })
    })

    $("#loginOut").on("click",function(){
        $.getJsonData(fullServerPath+"/users/logout",{},{type:"Post"}).done(function(data){
            if(data.success){
                moon.info("退出","top");
                window.location.href = contextPath+"login.html";
            }else{
                moon.error("退出失败","top");
            }
        })
    })

    //添加表单验证
    $("#deviceForm").validate({align:'bottom',theme:"darkblue"});

})






